#include "wxssashlayoutwindow.h"
#include <wx/sashwin.h>
#include <wx/laywin.h>

namespace {
  wxsRegisterItem<wxsSashLayoutWindow> Reg( _T( "SashLayoutWindow" ), _T( "窗扇布局窗口" ), wxsTContainer, _T( "布局" ), 50, false );
  WXS_ST_BEGIN( wxsSashLayoutWindowStyles, _T( "wxSW_3D|wxCLIP_CHILDREN" ) )
  WXS_ST_CATEGORY( "wxSashLayoutWindow" )
  WXS_ST( wxSW_3D )
  WXS_ST( wxSW_3DSASH )
  WXS_ST( wxSW_3DBORDER )
  WXS_ST( wxSW_BORDER )
  WXS_ST_DEFAULTS()
  WXS_ST_END()
  WXS_EV_BEGIN( wxsSashLayoutWindowEvents )
  WXS_EVI( EVT_SASH_DRAGGED,      wxEVT_SASH_DRAGGED,      wxSashEvent, SashDragged )
  WXS_EVI( EVT_QUERY_LAYOUT_INFO, wxEVT_QUERY_LAYOUT_INFO, wxQueryLayoutInfoEvent, SashQueryLayout )
  WXS_EVI( EVT_CALCULATE_LAYOUT,  wxEVT_CALCULATE_LAYOUT,  wxCalculateLayoutEvent, SashCalculateLayout )
  WXS_EV_DEFAULTS()
  WXS_EV_END()
}

wxsSashLayoutWindow::wxsSashLayoutWindow( wxsItemResData* Data ):
  wxsContainer( Data, &Reg.Info, wxsSashLayoutWindowEvents, wxsSashLayoutWindowStyles ) {
  mTop    = true;
  mBottom = true;
  mLeft   = true;
  mRight  = true;
  mAlign  = wxLAYOUT_LEFT;
  mOrient = wxLAYOUT_HORIZONTAL;
}

wxObject* wxsSashLayoutWindow::OnBuildPreview( wxWindow* Parent, long Flags ) {
  wxSashLayoutWindow* swin = new wxSashLayoutWindow( Parent, GetId(), Pos( Parent ), Size( Parent ), Style() );
  SetupWindow( swin, Flags );
  swin->SetSashVisible( wxSASH_TOP, mTop );
  swin->SetSashVisible( wxSASH_BOTTOM, mBottom );
  swin->SetSashVisible( wxSASH_LEFT, mLeft );
  swin->SetSashVisible( wxSASH_RIGHT, mRight );
  if( mAlign == wxLAYOUT_TOP ) {
    swin->SetAlignment( wxLAYOUT_TOP );
  } else if( mAlign == wxLAYOUT_BOTTOM ) {
    swin->SetAlignment( wxLAYOUT_BOTTOM );
  } else if( mAlign == wxLAYOUT_LEFT ) {
    swin->SetAlignment( wxLAYOUT_LEFT );
  } else if( mAlign == wxLAYOUT_RIGHT ) {
    swin->SetAlignment( wxLAYOUT_RIGHT );
  }
  if( mOrient == wxLAYOUT_HORIZONTAL ) {
    swin->SetOrientation( wxLAYOUT_HORIZONTAL );
  } else {
    swin->SetOrientation( wxLAYOUT_VERTICAL );
  }
  AddChildrenPreview( swin, Flags );
  return swin;
}

void wxsSashLayoutWindow::OnBuildCreatingCode() {
  switch( GetLanguage() ) {
  case wxsCPP:
    AddHeader( _T( "<wx/sashwin.h>" ), GetInfo().ClassName, 0 );
    AddHeader( _T( "<wx/laywin.h>" ), GetInfo().ClassName, 0 );
    Codef( _T( "%C(%W, %I, %P, %S, %T, %N);\n" ) );
    BuildSetupWindowCode();
    AddChildrenCode();
    Codef( _T( "%ASetSashVisible(wxSASH_TOP,    %b);\n" ), mTop );
    Codef( _T( "%ASetSashVisible(wxSASH_BOTTOM, %b);\n" ), mBottom );
    Codef( _T( "%ASetSashVisible(wxSASH_LEFT,   %b);\n" ), mLeft );
    Codef( _T( "%ASetSashVisible(wxSASH_RIGHT,  %b);\n" ), mRight );
    if( mAlign == wxLAYOUT_TOP ) {
      Codef( _T( "%ASetAlignment(wxLAYOUT_TOP);\n" ) );
    } else if( mAlign == wxLAYOUT_BOTTOM ) {
      Codef( _T( "%ASetAlignment(wxLAYOUT_BOTTOM);\n" ) );
    } else if( mAlign == wxLAYOUT_LEFT ) {
      Codef( _T( "%ASetAlignment(wxLAYOUT_LEFT);\n" ) );
    } else if( mAlign == wxLAYOUT_RIGHT ) {
      Codef( _T( "%ASetAlignment(wxLAYOUT_RIGHT);\n" ) );
    }
    if( mOrient == wxLAYOUT_HORIZONTAL ) {
      Codef( _T( "%ASetOrientation(wxLAYOUT_HORIZONTAL);\n" ) );
    } else
    { Codef( _T( "%ASetOrientation(wxLAYOUT_VERTICAL);\n" ) ); }
    break;
  case wxsUnknownLanguage:
  default:
    wxsCodeMarks::Unknown( _T( "wxsSashLayoutWindow::OnBuildCreatingCode" ), GetLanguage() );
  }
}


void wxsSashLayoutWindow::OnEnumContainerProperties( M_Code_unused long Flags ) {
  static const long    valign[] = {    wxLAYOUT_TOP,       wxLAYOUT_LEFT,       wxLAYOUT_RIGHT,       wxLAYOUT_BOTTOM,   0};
  static const wxChar *nalign[] = {_T( "wxLAYOUT_TOP" ), _T( "wxLAYOUT_LEFT" ), _T( "wxLAYOUT_RIGHT" ), _T( "wxLAYOUT_BOTTOM" ), 0};
  static const long    vorient[] = {    wxLAYOUT_HORIZONTAL,       wxLAYOUT_VERTICAL,   0};
  static const wxChar *norient[] = {_T( "wxLAYOUT_HORIZONTAL" ), _T( "wxLAYOUT_VERTICAL" ), 0};
  WXS_BOOL( wxsSashLayoutWindow, mTop,    _T( "Drag Top" ),    _T( "dragtop" ),    true );
  WXS_BOOL( wxsSashLayoutWindow, mBottom, _T( "Drag Bottom" ), _T( "dragbottom" ), true );
  WXS_BOOL( wxsSashLayoutWindow, mLeft,   _T( "Drag Left" ),   _T( "dragleft" ),   true );
  WXS_BOOL( wxsSashLayoutWindow, mRight,  _T( "Drag Right" ),  _T( "dragright" ),  true );
  WXS_ENUM( wxsSashLayoutWindow, mAlign,  _T( "Alignment" ),   _T( "alignment" ),   valign,  nalign,  wxLAYOUT_LEFT );
  WXS_ENUM( wxsSashLayoutWindow, mOrient, _T( "Orientation" ), _T( "orientation" ), vorient, norient, wxLAYOUT_HORIZONTAL );
}


bool wxsSashLayoutWindow::OnCanAddChild( M_Code_unused wxsItem* Item, M_Code_unused bool ShowMessage ) {
  return true;
}
